import { Chart } from "@antv/g2";
import { Http } from "@b/model/base/http";
import { REANIMATIONTIME, EQUIPMENT } from "@b/model/enum";
export class BoxTopRight {
    chart?: Chart;
    chart1?: Chart;
    timer: any;
    width: number;
    height: number
    constructor(width: string, height: string) {
        this.timer = null
        this.width = parseInt(width) / 4
        this.height = parseInt(height) - 20
    }
    init(id1: string, id2: string) {
        const { width, height } = this
        this.chart1 = new Chart({
            container: document.getElementById(id1) as HTMLElement,
            width, height,
            theme: 'classicDark'
        })
        this.chart = new Chart({
            container: document.getElementById(id2) as HTMLElement,
            width, height,
            theme: 'classicDark'
        })
        this.chart1.data([]).interval()
            .transform({ type: 'stackEnter', groupBy: 'x' })
            .axis('x', { grid: false, title: false, tick: false, labelFill: '#f9e433', labelFontSize: 14, labelOpacity: 1 })
            .axis('y', { grid: false, title: false })
            .encode('x', 'year')
            .encode('y', 'value')
            .encode('color', 'type')
            .encode('series', 'type')
            .encode('enterDuration', 1000);
        this.chart.data([]).interval()
            .transform({ type: 'stackEnter', groupBy: 'x' })
            .axis('x', { grid: false, title: false, tick: false, labelFill: '#f9e433', labelFontSize: 14, labelOpacity: 1 })
            .axis('y', { grid: false, title: false, position: 'right' })
            .encode('x', 'year')
            .encode('y', 'value')
            .encode('color', 'type')
            .encode('series', 'type')
            .encode('enterDuration', 1000);
        this.chart1.render();
        this.chart.render();
    }
    async changeData(search: string) {
        clearTimeout(this.timer)
        const res = [
            { type: '单导心电', year: '总体异常率', value: 2600 },
            { type: '12导心电', year: '总体异常率', value: 1000 }
        ]
        const res1 = [
            { type: '单导心电', year: '今日异常率', value: 210 },
            { type: '12导心电', year: '今日异常率', value: 150 }
        ]
        this.chart?.changeData(res)
        this.chart1?.changeData(res1)
        this.timer = setTimeout(() => {
            this.changeData(search)
        }, REANIMATIONTIME);
    }
}